Skip to content

Fix/share always backfill full task#116

Merged
krzychdre merged 3 commits into
mainfrom
fix/share-always-backfill-full-task
Jun 22, 2026
Merged

Fix/share always backfill full task#116
krzychdre merged 3 commits into
mainfrom
fix/share-always-backfill-full-task

Conversation

@krzychdre

Copy link
Copy Markdown
Owner

No description provided.

…le self-hosted stack

Primary fix
-----------
OAuth callback returned 502 after Authentik login. Root cause: Authentik
routes to its /application/o/* endpoints by HTTP Host header and rejects
hosts with an underscore (auth_server is not a valid RFC-1123 hostname)
with a 404, so back-channel token exchange to http://auth_server:9000
failed and the API rendered its own 502 page.

The api now connects to AUTHENTIK_INTERNAL_URL for networking but presents
the front-channel host (host of AUTHENTIK_BASE_URL, e.g. localhost:9000 or
auth.tumblecode.dev) as the Host header on token/userinfo/discovery calls.
Topology-independent: works for the bundled dev stack and a public
app.tumblecode.dev deployment alike.

- config/auth.py: get_back_channel_host_header()
- src/auth/authentik.py: _back_channel_headers() on the 3 back-channel calls
- tests/test_back_channel_host.py: header value + attachment on all calls
- README.md / .env.example: Host-override rationale + production block

Verified live against the running Authentik: old Host (auth_server:9000)
-> 404; new Host (localhost:9000) + real client_secret + fake code ->
400 invalid_grant (request reaches the endpoint, client auth passes).

Also includes the in-progress self-hosted stack snapshot
-------------------------------------------------------
Bundled Authentik (server/worker/Postgres/Redis) + blueprint, Dockerfile
entrypoint with db_bootstrap (FRESH/LEGACY/MANAGED), Makefile, web view
tweaks, and the accompanying ai_plans docs.
Share only backfilled the full task.json on a 404 (TaskNotFoundError),
assuming any existing server row was complete. When the live bridge had
created a partial row (it connected mid-task and captured only later
messages, while the offline-run opening turns were never uploaded), share
returned 200, backfill was skipped, and the partial copy was shared — the
web view showed tokens/cost (from api_req_started rows) but "Untitled
task" and no conversation.

Backfill the authoritative full local history before sharing whenever
messages are available; keep the 404 path as a best-effort retry.
backfill_messages replaces the task's stored rows, so this is idempotent.
The cloud web view labels a task's worktree from task.workspace_path,
stamped once and never overwritten. For live (bridge) tasks the first
stamp read the path from a per-user registry that tracks only one
extension instance ('newest wins'), and the message event didn't carry
which window produced it. With multiple windows under one account, a
task could be stamped with another window's worktree.

Carry the originating window's workspacePath on each Message bridge
event and prefer it over the registry singleton on the backend,
mirroring the share/backfill path.
@krzychdre krzychdre merged commit c167a90 into main Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant