Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions connector/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,32 @@ def main() -> int:
return 3

client = BackendClient(cfg.backend_url)
# Keep localhost:8099 reachable while backend activation is pending.
start_admin(state, cfg, client, store, cfg.admin_port)
state.log(f"Admin UI on http://localhost:{cfg.admin_port}")

# Native installer writes a pending setup config before starting the service.
# It must take precedence over credentials left by an older installation.
wizard = load_wizard_config()
if wizard and apply_pending_source_update(wizard):
wizard = load_wizard_config()
state.log("Installer source update applied; activation is pending")

stop = threading.Event()
wizard_ready = threading.Event()
pending_setup = bool(wizard and not wizard.setup_complete)

def _on_wizard_configured(_wizard_cfg) -> None:
wizard_ready.set()

# Keep localhost:8099 reachable while backend activation is pending.
start_admin(
state,
cfg,
cfg.admin_port,
store=store,
enable_setup_wizard=pending_setup,
on_wizard_configured=_on_wizard_configured if pending_setup else None,
Comment on lines +313 to +314

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Wizard completion loops forever 🐞 Bug ≡ Correctness

If /setup completes during the native-installer retry sleep, the reloaded wizard has
setup_complete=True, causing _provision_native_installer to return False and the `while not
...` loop to retry indefinitely. The connector remains degraded and never starts monitoring until
restarted.
Agent Prompt
## Issue description
The setup wizard is now available concurrently with the native-installer retry loop. If the wizard completes during the retry delay, `_provision_native_installer` returns `False` for the completed configuration, which the loop interprets as another provisioning failure and repeats indefinitely.

## Issue Context
Treat persisted wizard completion or `wizard_ready` as successful setup and continue into monitoring. Do not rely only on the callback because setup may complete through another path; add coverage for completion during the retry delay.

## Fix Focus Areas
- connector/app/main.py[318-332]
- connector/app/main.py[214-217]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

)
state.log(f"Admin UI on http://localhost:{cfg.admin_port}")

if cfg.service_mode and wizard and not wizard.setup_complete:
while not _provision_native_installer(cfg, wizard, client, store, state):
state.degraded_reason = (
Expand Down Expand Up @@ -344,22 +360,6 @@ def main() -> int:
state.connector_id = client.connector_id
state.log(f"Loaded existing connector credentials ({client.connector_id})")

stop = threading.Event()
wizard_ready = threading.Event()

def _on_wizard_configured(_wizard_cfg) -> None:
wizard_ready.set()

start_admin(
state,
cfg,
cfg.admin_port,
store=store,
enable_setup_wizard=activation_failed,
on_wizard_configured=_on_wizard_configured if activation_failed else None,
)
state.log(f"Admin UI on http://localhost:{cfg.admin_port}")

if activation_failed:
try:
while not wizard_ready.is_set():
Expand Down
11 changes: 10 additions & 1 deletion connector/app/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LocalStore:
def __init__(self, state_dir: str):
os.makedirs(state_dir, exist_ok=True)
self.path = os.path.join(state_dir, "connector.sqlite")
self._conn = sqlite3.connect(self.path, check_same_thread=False)
self._conn: sqlite3.Connection | None = sqlite3.connect(self.path, check_same_thread=False)
self._lock = threading.RLock()
self._conn.execute("PRAGMA busy_timeout=5000;")
self._conn.execute("PRAGMA journal_mode=WAL;")
Expand Down Expand Up @@ -127,3 +127,12 @@ def purge_done_failed(self) -> int:
)
self._conn.commit()
return cur.rowcount

def close(self) -> None:
with self._lock:
if self._conn is not None:
try:
self._conn.close()
except Exception:
pass
self._conn = None
Loading