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
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ merge; repository-authored evidence alone is not authority.
and adds bounded passive-PDF text extraction inside the existing isolated
child.

03B3B3A is the active successor. It installs only the approved `defusedxml`
wheel and adds the shared bounded OPC/OOXML container security capability. It
does not activate a DOCX, PPTX, or XLSX extractor, AUTH, or sufficiency.
03B3B3A merged through PR #233. It installs only the approved `defusedxml`
wheel and adds the shared bounded OPC/OOXML container security capability.
03B3B3B is the active successor. Its bounded DOCX extraction and durable
omission-fact implementation passed focused tests and required internal review;
hosted CI, CodeRabbit, and human merge remain pending. PPTX, XLSX, image, AUTH,
and sufficiency work remain inactive.

AUTH `WS-XINT-002-04B` follows the complete hidden split-03B series and
activates only fixed-service binding and guide read. ART-03C then removes the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ P2
```text
backend/app/modules/artifacts/guide_docx.py
backend/app/modules/artifacts/guide_extraction.py
backend/app/modules/artifacts/guide_extraction_service.py
backend/app/modules/artifacts/guide_extraction_worker.py
backend/scripts/run_test_lanes.py
backend/tests/test_artifact_architecture.py
backend/tests/test_guide_docx.py
backend/tests/test_guide_extraction.py
backend/tests/test_guide_bindings.py
backend/tests/fixtures/guide_docx/**
backend/tests/fixtures/guide_extraction_probe_worker.py
docs/spec_artifact_storage_service.md
.agent-loop/initiatives/WS-ART-001-immutable-artifact-storage/**
```
Expand All @@ -50,16 +56,39 @@ PPTX/XLSX behavior, package additions beyond approved lock, framework/AUTH/Celer
comments, tracked-deletion text, and embedded objects are omitted and
recorded in omission facts. Streaming stops with `limit_exceeded` before
exceeding D42's 4 MiB canonical-output limit; no partial result is usable.
- Canonical DOCX output is compact sorted JSON with one `blocks` array. A
paragraph block is `{"type":"paragraph","text":"..."}`. A table block is
`{"type":"table","text":"..."}` with tab between cells, newline between
rows, newline between multiple paragraphs in a cell, and a newline on each
side of a nested table when adjacent cell content exists. Empty paragraphs,
rows, and cells remain explicit. `w:t` and visible field-result text are
retained; `w:tab` becomes tab and `w:br|w:cr` becomes newline. Hyperlink
display text stays in document order. Field instructions, hidden text,
comment markers, tracked deletions, drawings, pictures, and other passive
non-text body objects are omitted. Active embedded package content remains a
malformed OOXML rejection before DOCX extraction. Traversal deeper than 64
nested document/container levels returns stable `malformed` evidence.
- Successful DOCX omission facts have the fixed bounded boolean schema
`truncated`, `omitted`, `headers`, `footers`, `comments`,
`tracked_deletions`, `embedded_objects`, `hidden_text`, and
`field_instructions`. The existing isolated-child result protocol carries these
facts; other formats retain the exact default
`{"truncated":false,"omitted":false}`. Persistence binds and replay-checks
omission facts with the canonical output. DOCX uses exact policy identity
`guide-extraction-v3`, so obsolete unsupported evidence cannot replay.
- Import the parser only in the isolated child and prove deterministic output,
malformed/unsafe input, exact output boundary, crash, timeout, cancellation,
cleanup, approval-gate, and coverage behavior.
- Assign the focused DOCX test module to an existing canonical hosted semantic
lane without changing lane or coverage policy.

## Verification commands

```bash
(cd backend && uv run ruff check app tests)
(cd backend && python scripts/check_guide_extractor_dependencies.py)
(cd backend && uv run pytest -q tests/test_guide_ooxml.py tests/test_guide_docx.py tests/test_guide_extraction.py --cov=app.modules.artifacts --cov-report=term-missing --cov-fail-under=90)
(cd backend && uv run python scripts/check_guide_extractor_dependencies.py)
(cd backend && uv run pytest -q tests/test_guide_ooxml.py tests/test_guide_docx.py tests/test_guide_extraction.py tests/test_guide_bindings.py tests/test_artifact_architecture.py)
(cd backend && uv run pytest -q tests/test_guide_docx.py --cov=app.modules.artifacts.guide_docx --cov-report=term-missing --cov-fail-under=90)
(metadata_dir="$(mktemp -d)" && trap 'rm -rf "$metadata_dir"' EXIT && (cd backend && WORKSTREAM_TEST_ADMIN_DATABASE_URL=postgresql+asyncpg://workstream:workstream@localhost:5433/postgres .venv/bin/python scripts/run_isolated_tests.py --metadata-json "$metadata_dir/result.json" --timeout-seconds 12600 -- .venv/bin/python -m pytest -q --ignore=tests/test_isolated_database_runner.py --cov=app --cov-report=term-missing --cov-fail-under=78))
python3 scripts/check_stale_artifact_contracts.py
python3 scripts/check_markdown_links.py
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# External Review Response: WS-ART-001-03B3B3B

## Comments addressed

- GitHub Agent Gates flagged `worker protocol` as stale human-worker
vocabulary in the chunk contract and storage specification. Both references
now say `isolated-child result protocol`, and the exact stale authorization
documentation check passes locally.
- The first Backend gate reported `current_node_inventory_mismatch`. The DOCX
database-test parameter used generated ZIP bytes as its pytest ID, so ZIP
timestamps changed the collected node between the lane and independent
inventory passes. Stable explicit `json` and `docx` IDs now make repeated
collections identical.
- CodeRabbit reported four valid DOCX hardening/test gaps. The extractor now
returns stable `malformed/docx_nesting_limit` beyond 64 recursive levels,
preserves `w:sdt`-wrapped rows and cells, resolves validated OOXML part names
through their case-folded stored-name map, and proves the full nine-key
omission schema across the isolated-child JSON round trip.

## Comments deferred

None.

## Human decisions needed

None.

## Commands rerun

- `python3 scripts/check_stale_authorization_docs.py`
- `python3 scripts/check_markdown_links.py`
- `git diff --check`
- repeated `pytest --collect-only` for the affected binding module
- `ruff check tests/test_guide_bindings.py`
- `ruff check app tests scripts`
- focused DOCX/OOXML/extraction/architecture/lane suite (154 passed)
- DOCX coverage suite (12 passed, 93.24 percent)

## Remaining risks

Hosted Backend/Agent Gates and CodeRabbit completion remain required on the
repaired PR head before merge readiness.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Internal Review Evidence: WS-ART-001-03B3B3B

Reviewed against trusted main: `2f441e99f1af`

Reviewed at: `2026-07-31`

## Candidate

Hidden deterministic DOCX extraction on the merged shared OOXML boundary. The
candidate emits bounded canonical content and durable omission facts without
activating AUTH, guide sufficiency, PPTX/XLSX, or contributor submissions.

## Deterministic Evidence

- Ruff, approved extractor-dependency gate, stale artifact contracts, stale
wording, Markdown links, lane integrity, and `git diff --check`: PASS;
- focused DOCX, OOXML, extraction, architecture, and lane suite: 154 passed;
- focused DOCX adapter suite: 12 passed at 93.24 percent coverage;
- DB-backed binding/replay tests and repository-wide coverage remain delegated
to the hosted sharded Backend gate; no local full-suite run was used.

## Reviewer Results

| Reviewer | Result | Blocking findings |
|---|---|---|
| architecture | PASS | none |
| security/auth | PASS WITH LOW RISKS | none |
| QA/test | PASS WITH LOW RISKS | none |
| senior engineering | PASS WITH LOW RISKS | none |
| product/ops | PASS WITH LOW RISKS | none |
| reuse/dedup | PASS WITH LOW RISKS | none |
| CI integrity | PASS | none |
| test delta | PASS | none |
| docs | PASS | none |

## Material Repairs

- made body traversal omission-aware so block-level deletions and move-from
content cannot enter canonical output;
- covered direct, inherited character, inherited paragraph, and document-
default hidden-text semantics and recorded simple-field instructions;
- restored the worker-owned shared OOXML loader instead of adding a second
production validation path;
- made omission facts part of the bounded worker protocol, immutable persisted
evidence, and replay identity;
- corrected invalid-protocol tests so every assertion reaches its intended
validation branch;
- documented the exact canonical blocks and fixed omission schema.
- bounded recursive traversal, preserved content-control-wrapped rows/cells,
and resolved case-variant validated OOXML part names after external review.

## Accepted Low Risks

- Explicit false values on `w:vanish` are conservatively treated as hidden;
exact WordprocessingML visibility fidelity can be hardened later.
- The isolated child assembles a bounded block before the exact 4 MiB final
check; existing input, decompression, memory, CPU, wall-time, and parent
protocol limits prevent partial durable output.
- Parent and child deliberately repeat their small omission schemas so the
isolated protocol is independently validated; future formats should avoid
allowing those literals to proliferate.

Valid findings addressed: yes

Open sub-agent sessions: none
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# WS-ART-001-03B3B3B PR Trust Bundle

## Chunk

`WS-ART-001-03B3B3B` — DOCX Extractor (L1).

## Goal and human-approved intent

Add deterministic, bounded DOCX text and table extraction after exact DOCX
classification and the merged OOXML security boundary. Preserve original
verified guide bytes as authoritative. This hidden chunk must not activate
AUTH, invoke guide sufficiency, add other formats, or touch contributor ZIPs.

## What changed and why

- Added an isolated DOCX adapter that emits compact sorted JSON blocks in
document order with fixed paragraph, row, cell, and nested-table semantics.
- Added a fixed omission schema for headers, footers, comments, deletions,
passive objects, hidden text, and field instructions.
- Advanced DOCX evidence to `guide-extraction-v3` and bound omission facts to
immutable persistence and replay checks.
- Reused the existing worker-owned OOXML validator loader and kept both the
validator and DOCX adapter imports confined to the isolated child.
- Added focused tests, the existing hosted semantic lane assignment, and the
exact storage-service contract.

## Design chosen and alternatives rejected

The isolated worker composes the shared OOXML validator with the DOCX adapter
before descriptor-only seccomp. The adapter receives an explicit validator,
then parses only validated `word/document.xml` and bounded style facts. The
parent accepts only the exact result and omission schemas. Rejected alternatives
were upload-request parsing, direct provider access, a second OOXML validation
path, raw binary agent input, partial output, or generic document authority.

## Scope control and product behavior

Only hidden guide-source extraction changes. There is no route, authorization
activation, Celery continuation, sufficiency invocation, provider read, guide
binding, submission, checker, review, contribution, payment, or reputation
change. Unsupported and malformed content remains a bounded internal artifact
outcome, not a guide-insufficiency decision.

## Acceptance criteria proof

- Paragraphs, hyperlinks, tabs, breaks, tables, cells, nested tables, and empty
structures have exact canonical output tests.
- Headers, footers, comments, tracked deletion/move-from content, passive
objects, fields, direct/inherited style-hidden text, and document-default
hidden text are omitted and recorded.
- Active content and malformed XML fail through stable bounded outcomes.
- Exact output-limit behavior returns no partial usable result.
- The real isolated runner proves v3 policy, omission transport, and scratch
cleanup; architecture tests prove worker-only adapter/validator imports.
- Persistence tests bind canonical output and omission facts and reject obsolete
policy evidence as a replay target.

## Tests and checks

- Ruff and approved extractor-dependency gate — pass.
- Focused DOCX/OOXML/extraction/architecture/lane suite — 154 passed.
- DOCX module coverage — 93.24 percent (12 tests).
- Stale artifact contracts, stale wording, Markdown links, lane integrity, and
`git diff --check` — pass.
- Hosted Backend/Agent Gates retain DB-backed replay, repository-wide coverage,
and semantic-lane proof; no local full-suite run was used.

## Test delta and CI integrity

No test, assertion, lane, workflow, dependency rule, or coverage threshold was
removed, skipped, or weakened. Invalid result-shape fixtures carry valid
omission facts so they still reach their intended validation branches. The new
DOCX module joins the existing `shared_foundations` lane.

## Reviewer results

Architecture, CI integrity, test delta, and docs pass. Security, QA, senior
engineering, product/ops, and reuse/dedup pass with only documented low risks.
All blocking deletion traversal, hidden-style cascade, isolated-runner, shared-
loader reuse, protocol-test, and documentation findings were repaired and
re-reviewed.

## External review

The first Agent Gates run found two stale human-worker vocabulary matches; both
now use the exact isolated-child result-protocol wording and the local gate
passes. The first Backend run exposed a nondeterministic raw-ZIP pytest ID;
explicit stable format IDs now produce identical repeated collections.
CodeRabbit's first attempt was rate-limited without code findings and must be
retriggered. Its completed review then identified four valid gaps: recursive
depth, content-control-wrapped rows/cells, case-folded part resolution, and the
cross-process omission assertion. All four are repaired with focused regression
proof. Hosted checks remain required on the repaired PR head.

## Remaining risks and follow-up

DOCX has a large visibility model; this chunk intentionally supports a bounded
subset and treats `w:vanish` presence conservatively, including explicit false
values. Future formats should reuse the same isolated result protocol without
growing duplicated schemas. PPTX/XLSX, durable sufficiency continuation, and
AUTH activation remain separate later chunks.

## Human review focus and merge ownership

Review exact canonical ordering/separators, omission semantics, injected shared
OOXML validation, v3 replay identity, isolation, and absence of AUTH or
sufficiency activation. A human owns merge approval; the agent will not merge
this PR.
Loading
Loading